package com.dckeji.shiplock.webapp.service.impl;

import com.dckeji.shiplock.webapp.dao.ITimeOutApplyDao;
import com.dckeji.shiplock.webapp.pojo.TimeOutApply;
import com.dckeji.shiplock.webapp.service.ITimeOutApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: TianWei
 * Date: 2017/8/9
 * Time: 11:46
 */
@Service
public class TimeOutApplyServiceImpl implements ITimeOutApplyService {
    @Autowired
    ITimeOutApplyDao timeOutApplyDao;

    @Override
    public int timeOutApply(TimeOutApply timeOutApply) {
        return timeOutApplyDao.timeOutApply(timeOutApply);
    }

    @Override
    public List<TimeOutApply> queryTimeOutApplyList() {
        List<TimeOutApply> result = new ArrayList<>();
        List<TimeOutApply> timeOutApplies = timeOutApplyDao.queryTimeOutApplyList();
        for (TimeOutApply t : timeOutApplies) {
            String timeOutVocherUrls = t.getTimeOutVocherUrls();
            String[] urls = timeOutVocherUrls.split(",");
            t.setVoucher1(urls[0]);
            t.setVoucher2(urls[1]);
            t.setVoucher3(urls[2]);
            t.setVoucher4(urls[3]);
            result.add(t);
        }
        return result;
    }
}
